import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './routes'
import { getToken } from '../utils/session'
import { ElMessage } from "element-plus"

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from , next) => {
  if(to.meta.isAuth) {
    if(getToken()) {
      next()
    } else {
      ElMessage({
        type: 'warning',
        message: '未登录'
      })
      router.push({path: '/login'})
    }
  } else {
    next()
  }
})
export default router